<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let p1 = new Promise(resolve => {
            setTimeout(resolve, 200, 1)
        });
        let p2 = new Promise((resolve, reject) => reject(2));
        let p3 = 3;
        console.log(Promise.allSettled([p1, p2, p3]));

        function allSettled(promises) {
            return new Promise((resolve, reject) => {
                const results = [];
                const len = promises.length;
                let resolvedCount = 0;
                for (let i = 0; i < len; i++) {
                    promises[i]
                        .then((value) => {
                            results[i] = { status: "fulfilled", value };
                        })
                        .catch((reason) => {
                            results[i] = { status: "rejected", reason };
                        })
                        .finally(() => {
                            resolvedCount++;
                            if (resolvedCount === len) {
                                resolve(results);
                            }
                        });
                }
            });
        }
    </script>
</body>

</html>